From fa4e7a31fd98737185dbeb073f710082f631f6c6 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Tue, 23 Oct 2001 23:35:00 +0000 Subject: [PATCH] only sensitize Cut if selection contains some editable text, #60975 2001-10-23 Havoc Pennington * gtk/gtktextview.c (popup_targets_received): only sensitize Cut if selection contains some editable text, #60975 (gtk_text_view_scroll_to_iter): remove warning about scrolling prior to map; it should actually be OK to do so in many cases, it would be nice to warn about scrolling when many lines have height 0, but I don't know what to do about that. Perhaps move part of flush_scroll into this function? comment added to consider this. --- ChangeLog | 11 +++++++++++ ChangeLog.pre-2-0 | 11 +++++++++++ ChangeLog.pre-2-10 | 11 +++++++++++ ChangeLog.pre-2-2 | 11 +++++++++++ ChangeLog.pre-2-4 | 11 +++++++++++ ChangeLog.pre-2-6 | 11 +++++++++++ ChangeLog.pre-2-8 | 11 +++++++++++ gtk/gtktextview.c | 38 +++++++++++++++++++++++++++++--------- 8 files changed, 106 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index fd67c8733b..7806eeffb9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2001-10-23 Havoc Pennington + + * gtk/gtktextview.c (popup_targets_received): only sensitize Cut + if selection contains some editable text, #60975 + (gtk_text_view_scroll_to_iter): remove warning about scrolling + prior to map; it should actually be OK to do so in many cases, + it would be nice to warn about scrolling when many lines have + height 0, but I don't know what to do about that. Perhaps + move part of flush_scroll into this function? comment added + to consider this. + 2001-10-23 Havoc Pennington * gtk/gtktextview.c (changed_handler): Correctly keep the same diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index fd67c8733b..7806eeffb9 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,14 @@ +2001-10-23 Havoc Pennington + + * gtk/gtktextview.c (popup_targets_received): only sensitize Cut + if selection contains some editable text, #60975 + (gtk_text_view_scroll_to_iter): remove warning about scrolling + prior to map; it should actually be OK to do so in many cases, + it would be nice to warn about scrolling when many lines have + height 0, but I don't know what to do about that. Perhaps + move part of flush_scroll into this function? comment added + to consider this. + 2001-10-23 Havoc Pennington * gtk/gtktextview.c (changed_handler): Correctly keep the same diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index fd67c8733b..7806eeffb9 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,14 @@ +2001-10-23 Havoc Pennington + + * gtk/gtktextview.c (popup_targets_received): only sensitize Cut + if selection contains some editable text, #60975 + (gtk_text_view_scroll_to_iter): remove warning about scrolling + prior to map; it should actually be OK to do so in many cases, + it would be nice to warn about scrolling when many lines have + height 0, but I don't know what to do about that. Perhaps + move part of flush_scroll into this function? comment added + to consider this. + 2001-10-23 Havoc Pennington * gtk/gtktextview.c (changed_handler): Correctly keep the same diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index fd67c8733b..7806eeffb9 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,14 @@ +2001-10-23 Havoc Pennington + + * gtk/gtktextview.c (popup_targets_received): only sensitize Cut + if selection contains some editable text, #60975 + (gtk_text_view_scroll_to_iter): remove warning about scrolling + prior to map; it should actually be OK to do so in many cases, + it would be nice to warn about scrolling when many lines have + height 0, but I don't know what to do about that. Perhaps + move part of flush_scroll into this function? comment added + to consider this. + 2001-10-23 Havoc Pennington * gtk/gtktextview.c (changed_handler): Correctly keep the same diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index fd67c8733b..7806eeffb9 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,14 @@ +2001-10-23 Havoc Pennington + + * gtk/gtktextview.c (popup_targets_received): only sensitize Cut + if selection contains some editable text, #60975 + (gtk_text_view_scroll_to_iter): remove warning about scrolling + prior to map; it should actually be OK to do so in many cases, + it would be nice to warn about scrolling when many lines have + height 0, but I don't know what to do about that. Perhaps + move part of flush_scroll into this function? comment added + to consider this. + 2001-10-23 Havoc Pennington * gtk/gtktextview.c (changed_handler): Correctly keep the same diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index fd67c8733b..7806eeffb9 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,14 @@ +2001-10-23 Havoc Pennington + + * gtk/gtktextview.c (popup_targets_received): only sensitize Cut + if selection contains some editable text, #60975 + (gtk_text_view_scroll_to_iter): remove warning about scrolling + prior to map; it should actually be OK to do so in many cases, + it would be nice to warn about scrolling when many lines have + height 0, but I don't know what to do about that. Perhaps + move part of flush_scroll into this function? comment added + to consider this. + 2001-10-23 Havoc Pennington * gtk/gtktextview.c (changed_handler): Correctly keep the same diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index fd67c8733b..7806eeffb9 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,14 @@ +2001-10-23 Havoc Pennington + + * gtk/gtktextview.c (popup_targets_received): only sensitize Cut + if selection contains some editable text, #60975 + (gtk_text_view_scroll_to_iter): remove warning about scrolling + prior to map; it should actually be OK to do so in many cases, + it would be nice to warn about scrolling when many lines have + height 0, but I don't know what to do about that. Perhaps + move part of flush_scroll into this function? comment added + to consider this. + 2001-10-23 Havoc Pennington * gtk/gtktextview.c (changed_handler): Correctly keep the same diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c index dedb043293..afd86f2aaf 100644 --- a/gtk/gtktextview.c +++ b/gtk/gtktextview.c @@ -1306,6 +1306,11 @@ gtk_text_view_scroll_to_iter (GtkTextView *text_view, gint scroll_inc; gint screen_xoffset, screen_yoffset; gint current_x_scroll, current_y_scroll; + + /* FIXME why don't we do the validate-at-scroll-destination thing + * from flush_scroll in this function? I think it wasn't done before + * because changed_handler was screwed up, but I could be wrong. + */ g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE); g_return_val_if_fail (iter != NULL, FALSE); @@ -1317,12 +1322,6 @@ gtk_text_view_scroll_to_iter (GtkTextView *text_view, DV(g_print(G_STRLOC"\n")); - if (!GTK_WIDGET_MAPPED (widget)) - { - g_warning ("gtk_text_view_scroll_to_iter(): calling this function before showing the GtkTextView doesn't make sense, maybe try gtk_text_view_scroll_to_mark() instead"); - return FALSE; - } - gtk_text_layout_get_iter_location (text_view->layout, iter, &rect); @@ -5476,6 +5475,24 @@ typedef struct guint time; } PopupInfo; +static gboolean +range_contains_editable_text (const GtkTextIter *start, + const GtkTextIter *end, + gboolean default_editability) +{ + GtkTextIter iter = *start; + + while (gtk_text_iter_compare (&iter, end) < 0) + { + if (gtk_text_iter_editable (&iter, default_editability)) + return TRUE; + + gtk_text_iter_forward_to_tag_toggle (&iter, NULL); + } + + return FALSE; +} + static void popup_targets_received (GtkClipboard *clipboard, GtkSelectionData *data, @@ -5495,7 +5512,8 @@ popup_targets_received (GtkClipboard *clipboard, gboolean have_selection; gboolean can_insert; GtkTextIter iter; - + GtkTextIter sel_start, sel_end; + if (text_view->popup_menu) gtk_widget_destroy (text_view->popup_menu); @@ -5506,7 +5524,7 @@ popup_targets_received (GtkClipboard *clipboard, popup_menu_detach); have_selection = gtk_text_buffer_get_selection_bounds (get_buffer (text_view), - NULL, NULL); + &sel_start, &sel_end); gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &iter, @@ -5515,7 +5533,9 @@ popup_targets_received (GtkClipboard *clipboard, can_insert = gtk_text_iter_can_insert (&iter, text_view->editable); append_action_signal (text_view, text_view->popup_menu, GTK_STOCK_CUT, "cut_clipboard", - have_selection); + have_selection && + range_contains_editable_text (&sel_start, &sel_end, + text_view->editable)); append_action_signal (text_view, text_view->popup_menu, GTK_STOCK_COPY, "copy_clipboard", have_selection); append_action_signal (text_view, text_view->popup_menu, GTK_STOCK_PASTE, "paste_clipboard", -- 2.30.2